import request from '@/utils/request.js'

// 在非组件模块下获取store必须通过这个方式获取
// 这里单独加载的store和在组件中this.$store加载是一样的
// import store from '@/store/'

// 登录注册
export const login = data => {
  return request({
    url: 'app/v1_0/authorizations',
    method: 'POST',
    data
  })
}

export const sendSms = (mobile) => {
  return request({
    url: `app/v1_0/sms/codes/${mobile}`,
    method: 'GET'
  })
}

// 获取登录的用户信息
export const getCurrentUser = () => {
  return request({
    url: 'app/v1_0/user',
    method: 'GET'
    // headers: {
    //   Authorization: `Bearer ${store.state.user.token}`
    // }
  })
}

// 获取首页用户频道
export const getUserChannels = () => {
  return request({
    url: 'app/v1_0/user/channels',
    method: 'GET'
  })
}

// 添加关注
export const addUserFollow = (userId) => {
  return request({
    url: 'app/v1_0/user/followings',
    method: 'POST',
    data: {
      target: userId
    }
  })
}

// 取消关注
export const deleteUserFollow = (userId) => {
  return request({
    url: `app/v1_0/user/followings/${userId}`,
    method: 'DELETE'
  })
}

export const getUserProfile = () => {
  return request({
    url: 'app/v1_0/user/profile',
    method: 'GET'
  })
}

export const updateUserProfile = (data) => {
  return request({
    url: 'app/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

export const updateUserPhoto = (data) => {
  return request({
    url: 'app/v1_0/user/photo',
    method: 'PATCH',
    data
  })
}
